#!/usr/local/bin/python

import sys,os,time,string,signal
import random
import l3dgecomms
import getstats
from getstats import Metric

#LAMS server
LAMS_IP="136.186.229.114"
LAMS_PORT=27960
LAMS_CONF="lams.conf"
POLL_TIME=20 #seconds

#Define in game metrics
METRIC_ONE=1
METRIC_TWO=2
METRIC_THREE=3
METRIC_FOUR=4
METRIC_FIVE=5
METRIC_SIX=6
METRIC_SEVEN=7
METRIC_EIGHT=8
METRIC_NINE=9
METRIC_TEN=10
METRIC_ZERO=0

METRIC_SPIN=METRIC_ONE
METRIC_BOUNCE_HEIGHT=METRIC_TWO
METRIC_SCALE=METRIC_THREE
METRIC_ROLL=METRIC_FOUR
METRIC_COLOR=METRIC_FIVE
METRIC_BOUNCE_RATE=METRIC_SIX 
METRIC_SOUND=METRIC_SEVEN
METRIC_ALT_SKIN=METRIC_EIGHT
METRIC_ALT_MODEL=METRIC_NINE 
METRIC_UNUSED=METRIC_TEN
METRIC_INFO=METRIC_ZERO

def sigHandler(signum, frame):
	print "Got signal " + str(signum)
	l3dgecomms.closeComms()
	print "Connection closed"
	sys.exit()
signal.signal(signal.SIGINT, sigHandler)

#setup l3dgecomms to talk to out LAMS server host
l3dgecomms.setupComms(None,0,LAMS_IP,LAMS_PORT)
print "Connected to LAMS"

#Define metrics
busyTraffic = Metric("Bytes In", METRIC_BOUNCE_HEIGHT,None,"112 Mbps","50")
busyServTraffic = Metric("Bytes In", METRIC_BOUNCE_HEIGHT,None,"80 Mbps","50")
normServTraffic = Metric("Bytes In", METRIC_BOUNCE_HEIGHT,None,"16 Mbps","10")
busyServCPU = Metric("CPU Usage", METRIC_SPIN,None,"97 %","100")
normServCPU = Metric("CPU Usage", METRIC_SPIN,None,"38 %","10")
normTraffic = Metric("Bytes In", METRIC_BOUNCE_HEIGHT,None,"32 Mbps","20")
deadColor = Metric("Connection Status",METRIC_COLOR,None,"Not Connected","9c9c9c")
warningColor = Metric("Warning",METRIC_ALT_SKIN,None,"Maximum Load","1")
clusterBusySpin = Metric("Current Calls",METRIC_SPIN,None,"19","100")
clusterNormSpin = Metric("Current Calls",METRIC_SPIN,None,"10","10")
astBusySpin = Metric("Current Calls",METRIC_SPIN,None,"9","100")
astAvgSpin = Metric("Current Calls",METRIC_SPIN,None,"5","10")
astStrangeDur = Metric("Avg Call Duration", METRIC_BOUNCE_RATE,None,"3.49 seconds","90")
astNormDur = Metric("Avg Call Duration", METRIC_BOUNCE_RATE,None,"4.87 minutes","20")
clientInCall = Metric("In Call", METRIC_SPIN,None,"Yes","30")

print "Sending updates"
#Geelong cluster
normTraffic.updateEntity(2)
clusterNormSpin.updateEntity(2)
#Melb cluster
busyTraffic.updateEntity(1)
warningColor.updateEntity(1)
clusterBusySpin.updateEntity(1)
#Melb dodgy server
warningColor.updateEntity(4)
astBusySpin.updateEntity(4)
astStrangeDur.updateEntity(4)
busyServTraffic.updateEntity(3)
busyServCPU.updateEntity(3)
#Melb  normal servers
astAvgSpin.updateEntity(6)
astNormDur.updateEntity(6)
astAvgSpin.updateEntity(8)
astNormDur.updateEntity(8)
normServTraffic.updateEntity(5)
normServTraffic.updateEntity(7)
normServCPU.updateEntity(7)
normServCPU.updateEntity(5)
#Busy clients
clientInCall.updateEntity(9)
warningColor.updateEntity(9)
clientInCall.updateEntity(10)
warningColor.updateEntity(10)
clientInCall.updateEntity(11)
warningColor.updateEntity(11)
clientInCall.updateEntity(12)
clientInCall.updateEntity(13)
clientInCall.updateEntity(14)
warningColor.updateEntity(14)
clientInCall.updateEntity(15)
clientInCall.updateEntity(16)
clientInCall.updateEntity(17)
warningColor.updateEntity(17)
#
clientInCall.updateEntity(18)
clientInCall.updateEntity(20)
clientInCall.updateEntity(21)
clientInCall.updateEntity(22)
clientInCall.updateEntity(25)
#
clientInCall.updateEntity(28)
clientInCall.updateEntity(29)
clientInCall.updateEntity(30)
clientInCall.updateEntity(32)
clientInCall.updateEntity(33)




